import pymysql
import requests
from lxml import etree
respons = requests.get("http://www.szeasyin.com/wh/24177.html").text
resp = etree.HTML(respons)
# print(resp)
txts =resp.xpath('//*[@id="divContent"]/p[61]/text()')
txts=txts[0]
txts = txts.split('、')
starts = 52106164983
i=0
try:
    conn = pymysql.Connection(host="192.168.0.113",port=3306,user='coname',password='xZS6p4LDcKCwn4Yb',db="co",charset="utf8")
    cursor = conn.cursor()
    print('连接数据库成功!')
except Exception as e:
    print("连接数据库失败!>>>",e)
try:
    for res0 in txts:
        i=i+1
        if not cursor.execute('select srname from co_fruit where srname="{}"'.format(res0)):
            cursor.execute('insert into co_fruit (srname,keywordid) values("{}","{}")'.format(res0,starts+i))
            conn.commit()
            print("插入"+res0+"成功")
except Exception as e:
    print('插入数据失败!>>>',e)
try:
    cursor.close()
    conn.close()
    print('关闭数据库成功!')
except Exception as e:
    print('连接数据库失败>>>',e)